layui.use(['form', 'fsoft'], function () {
	var $ = layui.$
		, form = layui.form
		, fsoft = layui.fsoft;
	var id = $('#id').val();
	var frmAction = {
		logout: function () { //退出系统
			fsoft.confirm("询 问", "确认要退出系统？", function (idx) {
				parent.location.href = layui.cache['contentPath'] + '/logout';
				layer.close(idx);
			});
		}
	};
	//退出系统监听
	$("#sysLogout").click(function () {
		frmAction.logout();
	});

	form.verify({
		loginPwdConfirm: function (value, item) {
			var loginPwd = $('input[name="loginPwd"]').val();
			if (loginPwd != value)
				return "两次密码不一致";
		}
		, loginPwdOld: function (value, item) { //原密码校验
			var base = new Base64();
			var params = { id: id, loginPwd: base.encode(value), method: 'post' };
			var errorMsg = null;
			fsoft.async(layui.cache['contentPath'] + '/sys-user/passworkCheck', params, function (rs) {
				if (rs.code != 0)
					errorMsg = rs.msg;
			}, false);
			if (errorMsg != null)
				return "原密码错误，请重新输入";
		}
	});
	// 监听提交
	form.on('submit(save)', function (data) {
		var formData = data.field;
		var base = new Base64();
		var loginPwd = formData.loginPwd;
		loginPwd = base.encode(loginPwd);
		formData["loginPwd"] = loginPwd;
		var submitParam = { id: id, loginPwd: loginPwd };
		fsoft.post(layui.cache['contentPath'] + '/sys-user/modifyPwd', submitParam, function (rs) {
			if (rs.code == 0) {
				fsoft.successMsg("密码修改成功！");
				xadmin.close();
			} else {
				fsoft.errorMsg(rs.msg);
				return false;
			}
		});
		return false;
	});
});